class Wall extends DisplayBase{
	private map:GameMap;
	public constructor(_map:GameMap) {
		super();
		this.map = _map;
	}

	public init(db:any){
		super.init(db);
		//创建一个墙壁
		this.createP2Body(db.w,db.h,db.x,db.y,db.resid,this.map.p2World,db.r);
	}


	private createP2Body(w:number,h:number,x:number,y:number,resid:string,world: p2.World,angle:number = 0){
        var factorc = 0.02;
        var factorx = 50;
        var stageHeight:number = this.map.stageHeight;//egret.MainContext.instance.stage.stageHeight;

        var boxShape: p2.Shape = new p2.Box({width: w*factorc, height: h*factorc});
        var boxBody: p2.Body = new p2.Body({ mass: 1, position: [(x+w*0.5)*factorc, (stageHeight - (y+h*0.5))*factorc]});
        boxBody.addShape(boxShape);
        world.addBody(boxBody);

        boxBody.type = p2.Body.KINEMATIC;
        boxBody.fixedRotation = true;
        boxBody.angle = angle;


        // var downDisplay:egret.DisplayObject = this.createBitmapByName(resid);
        // downDisplay.width = w;
        // downDisplay.height = h;
        // this.addChild(downDisplay);
		// this.x = x;
        // this.y = y;
        // this.anchorOffsetX = downDisplay.width / 2;
        // this.anchorOffsetY = downDisplay.height / 2;
        var tile_size:number = 64;
        var lens:number = Math.ceil(w/tile_size);
        for(var i:number = 0;i<lens;i++){
            var downDisplay:egret.DisplayObject = this.createBitmapByName(resid);
            downDisplay.width = tile_size;
            downDisplay.height = tile_size;
            downDisplay.x = i*tile_size;
            this.addChild(downDisplay);
        }

        this.anchorOffsetX = w / 2;
        this.anchorOffsetY = h / 2;

        // 
        // downDisplay.x = boxBody.position[0] * factorx;
        // downDisplay.y = stageHeight - boxBody.position[1] * factorx;

        // downDisplay.anchorOffsetX = downDisplay.width / 2;
        // downDisplay.anchorOffsetY = downDisplay.height / 2;
        // downDisplay.rotation = angle;

		

        this.rotation = angle;
        
        console.log('x='+this.x+'y='+this.y);

        console.log(downDisplay.x,downDisplay.y);
        
        boxBody.displays = [this];
    }
}